/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CaptchaView.java
 *
 * Created on 2011-06-06, 10:48:10
 */

package ytmc.uploader;

import ytmc.DialogView;

/**
 *
 * @author K
 */
public class CaptchaView extends DialogView
{
    private UploaderController controller;
    private String captchaToken;
    private String captchaURL;

    /** Creates new form CaptchaView */
    public CaptchaView(UploaderController controller, String captchaToken, String captchaURL)
    {
        this.controller = controller;
        this.captchaToken = captchaToken;
        this.captchaURL = captchaURL;

        initComponents();

        this.remoteImageView.setImegeURL(captchaURL);
        
        setLocationRelativeTo(null);
    }

    public void clear()
    {
        captchField.setText("");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        okBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        captchField = new javax.swing.JTextField();
        remoteImageView = new ytmc.RemoteImageView();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Przepisz tekst z obrazka");

        okBtn.setText("Ok");
        okBtn.setMaximumSize(new java.awt.Dimension(63, 23));
        okBtn.setMinimumSize(new java.awt.Dimension(63, 23));
        okBtn.setPreferredSize(new java.awt.Dimension(63, 23));
        okBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okBtnActionPerformed(evt);
            }
        });
        jPanel2.add(okBtn);

        cancelBtn.setText("Anuluj");
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnActionPerformed(evt);
            }
        });
        jPanel2.add(cancelBtn);

        remoteImageView.setBackground(new java.awt.Color(255, 255, 255));
        remoteImageView.setPreferredSize(new java.awt.Dimension(200, 70));

        javax.swing.GroupLayout remoteImageViewLayout = new javax.swing.GroupLayout(remoteImageView);
        remoteImageView.setLayout(remoteImageViewLayout);
        remoteImageViewLayout.setHorizontalGroup(
            remoteImageViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );
        remoteImageViewLayout.setVerticalGroup(
            remoteImageViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 70, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(captchField, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(remoteImageView, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(10, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(remoteImageView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(captchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_okBtnActionPerformed
    {//GEN-HEADEREND:event_okBtnActionPerformed
        controller.submitCaptcha(captchaToken, captchField.getText());
        this.setVisible(false);
    }//GEN-LAST:event_okBtnActionPerformed

    private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelBtnActionPerformed
    {//GEN-HEADEREND:event_cancelBtnActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_cancelBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelBtn;
    private javax.swing.JTextField captchField;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton okBtn;
    private ytmc.RemoteImageView remoteImageView;
    // End of variables declaration//GEN-END:variables

}
